//
//  SetViewController.m
//  markmap
//
//  Created by 甘世清 on 2024/5/6.
//

#import "SetViewController.h"
#import "MeTableViewCell.h"
#import "AboutViewController.h"
#import "ZhuXiaoViewController.h"
#import "LoginViewController.h"
#import "FeedbackViewController.h"
#import "BlackListViewController.h"
#import "xieyiView.h"
@interface SetViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"设置");
}

- (void)SQ_UIViewForSelfView{
    UIImageView * bg = [[UIImageView alloc]init];
    bg.image = SQGetImage(@"me背景");
    bg.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(TopHeight, 0, 0, 0));
    }];
    [self SQ_JsonArray];
}

-(void)SQ_JsonArray{
    [self.jsonArray removeAllObjects];
    NSArray * array = @[@"协议内容",@"问题反馈",@"拉黑列表",@"关于我们",@"注销账号",@"退出登录"];
    for (NSString * string in array) {
        [self.jsonArray addObject:string];
    }
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
     return self.jsonArray.count;
}
 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeTableViewCell"];
    if (!cell) {
        cell = [[MeTableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"MeTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.name =  [self.jsonArray objectAtIndex:indexPath.item];
    return cell;
}
 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  66;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString * name = [self.jsonArray objectAtIndex:indexPath.item];
    if ([name isEqualToString:@"拉黑列表"]) {
        BlackListViewController * vc = [[BlackListViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    }else if ([name isEqualToString:@"问题反馈"]) {
        FeedbackViewController * vc = [[FeedbackViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
   }else if ([name isEqualToString:@"协议内容"]) {
        [self SQ_ShareButtonClick];
    }else  if ([name isEqualToString:@"关于我们"]) {
        AboutViewController * vc = [[AboutViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    }else  if ([name isEqualToString:@"注销账号"]) {
        ZhuXiaoViewController * vc = [[ZhuXiaoViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    }else  if ([name isEqualToString:@"退出登录"]) {
        [self SQ_headerButtonClick];
    }
    
}
//协议
-(void)SQ_ShareButtonClick{
    xieyiView * view = [[xieyiView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, 170+FootHeight)];
    LSTPopView * pop = [LSTPopView initWithCustomView:view
                                           parentView:self.view
                                             popStyle:LSTPopStyleSmoothFromBottom dismissStyle:LSTDismissStyleSmoothToBottom];
    pop.hemStyle = LSTHemStyleBottom;
    pop.bgAlpha = 0.5;
    [pop pop];
    LSTPopViewWK(pop)
    [pop setBgClickBlock:^{
        [wk_pop dismiss];
    }];
}

-(void)SQ_headerButtonClick{
    WS(weakSelf);
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:SQNSLocalString(@"退出登录") message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction * co0 = [UIAlertAction actionWithTitle:SQNSLocalString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf SQ_buttonclick];
    }];
 
    UIAlertAction * co2 = [UIAlertAction actionWithTitle:SQNSLocalString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:co0];
    [alert addAction:co2];
    [self presentViewController:alert animated:YES completion:nil];
}

-(void)SQ_buttonclick{
    [UserModel clearLocalUserModel];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[LoginViewController alloc]init]];
     [Manager SQ_getCurrentViewController].view.window.rootViewController = nav;
}

@end
